<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="com.mysql.cj.xdevapi.JsonArray"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.Array"%>

 <%@ page import="java.io.IOException" %>
<%@page
import="java.io.PrintWriter"
import ="java.net.URLEncoder"
import=" java.sql.Connection"
import ="java.sql.DriverManager"
import ="java.sql.PreparedStatement"
import ="java.sql.ResultSet"
import ="javax.servlet.ServletException"
import=" javax.servlet.annotation.WebServlet"
import ="javax.servlet.http.HttpServlet"
import ="javax.servlet.http.HttpServletRequest"
import=" javax.servlet.http.HttpServletResponse"
import=" javax.swing.JOptionPane" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<% 
try {
	request.setCharacterEncoding("UTF-8");
    response.setContentType("text/html;charset=UTF-8");
	Class.forName("com.mysql.cj.jdbc.Driver");
	Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yj?autoReconnect=true&serverTimezone=GMT","root","root");	
	PreparedStatement p=con.prepareStatement("select * from zq where zqid=? ");
	p.setString(1, request.getParameter("zqid"));
	String name=new String();
	int count=0;
	ResultSet res=p.executeQuery();
while(res.next()){
	count=res.getInt("count");
	name=res.getString("goods");
}
	
PreparedStatement q=con.prepareStatement("select * from goods where ckid=? ");
		q.setString(1, request.getParameter("ckid"));
		ResultSet res2=q.executeQuery();
		while(res2.next()){
		if(name.equals("帐篷")){
			if(count<=res2.getInt("count1")){
				PreparedStatement k1=con.prepareStatement("update  zq  set count=0 where zqid=?");
				k1.setString(1, request.getParameter("zqid"));
				k1.executeUpdate();k1.close();
				PreparedStatement l1=con.prepareStatement("update  goods  set count1=? where ckid=?");
				l1.setInt(1, res2.getInt("count1")-count);
				l1.setString(2, request.getParameter("ckid"));
				l1.executeUpdate();l1.close();out.print("cg");
			}
			else{
				PreparedStatement l1=con.prepareStatement("update  goods  set count1=0 where ckid=?");
				l1.setString(1, request.getParameter("ckid"));
				l1.executeUpdate();l1.close();
				PreparedStatement k1=con.prepareStatement("update  zq  set count=? where zqid=?");
				k1.setInt(1, count-res2.getInt("count1"));
				k1.setString(2, request.getParameter("zqid"));
				k1.executeUpdate();k1.close();out.print("cg");
			}
		}
		
		if(name.equals("食品")){
			if(count<=res2.getInt("count2")){
				PreparedStatement k1=con.prepareStatement("update  zq  set count=0 where zqid=?");
				k1.setString(1, request.getParameter("zqid"));
				k1.executeUpdate();k1.close();
				PreparedStatement l1=con.prepareStatement("update  goods  set count2=? where ckid=?");
				l1.setInt(1, res2.getInt("count2")-count);
				l1.setString(2, request.getParameter("ckid"));
				l1.executeUpdate();l1.close();out.print("cg");
			}
			else{
				PreparedStatement l1=con.prepareStatement("update  goods  set count2=0 where ckid=?");
				l1.setString(1, request.getParameter("ckid"));
				l1.executeUpdate();l1.close();
				PreparedStatement k1=con.prepareStatement("update  zq  set count=? where zqid=?");
				k1.setInt(1, count-res2.getInt("count2"));
				k1.setString(2, request.getParameter("zqid"));
				k1.executeUpdate();k1.close();out.print("cg");
			}
		}
		if(name.equals("医疗物资")){
			if(count<=res2.getInt("count3")){
				PreparedStatement k1=con.prepareStatement("update  zq  set count=0 where zqid=?");
				k1.setString(1, request.getParameter("zqid"));
				k1.executeUpdate();k1.close();
				PreparedStatement l1=con.prepareStatement("update  goods  set count3=? where ckid=?");
				l1.setInt(1, res2.getInt("count3")-count);
				l1.setString(2, request.getParameter("ckid"));
				l1.executeUpdate();l1.close();out.print("cg");
			}
			else{
				PreparedStatement l1=con.prepareStatement("update  goods  set count3=0 where ckid=?");
				l1.setString(1, request.getParameter("ckid"));
				l1.executeUpdate();l1.close();
				PreparedStatement k1=con.prepareStatement("update  zq  set count=? where zqid=?");
				k1.setInt(1, count-res2.getInt("count3"));
				k1.setString(2, request.getParameter("zqid"));
				k1.executeUpdate();k1.close();out.print("cg");
			}
		}
		if(name.equals("水")){
			if(count<=res2.getInt("count4")){
				PreparedStatement k1=con.prepareStatement("update  zq  set count=0 where zqid=?");
				k1.setString(1, request.getParameter("zqid"));
				k1.executeUpdate();k1.close();
				PreparedStatement l1=con.prepareStatement("update  goods  set count4=? where ckid=?");
				l1.setInt(1, res2.getInt("count4")-count);
				l1.setString(2, request.getParameter("ckid"));
				l1.executeUpdate();l1.close();out.print("cg");
			}
			else{
				PreparedStatement l1=con.prepareStatement("update  goods  set count4=0 where ckid=?");
				l1.setString(1, request.getParameter("ckid"));
				l1.executeUpdate();l1.close();
				PreparedStatement k1=con.prepareStatement("update  zq  set count=? where zqid=?");
				k1.setInt(1, count-res2.getInt("count4"));
				k1.setString(2, request.getParameter("zqid"));
				k1.executeUpdate();k1.close();out.print("cg");
			}
		}
		if(name.equals("器械")){
			if(count<=res2.getInt("count5")){
				PreparedStatement k1=con.prepareStatement("update  zq  set count=0 where zqid=?");
				k1.setString(1, request.getParameter("zqid"));
				k1.executeUpdate();k1.close();
				PreparedStatement l1=con.prepareStatement("update  goods  set count5=? where ckid=?");
				l1.setInt(1, res2.getInt("count5")-count);
				l1.setString(2, request.getParameter("ckid"));
				l1.executeUpdate();l1.close();out.print("cg");
			}
			else{
				PreparedStatement l1=con.prepareStatement("update  goods  set count5=0 where ckid=?");
				l1.setString(1, request.getParameter("ckid"));
				l1.executeUpdate();l1.close();
				PreparedStatement k1=con.prepareStatement("update  zq  set count=? where zqid=?");
				k1.setInt(1, count-res2.getInt("count5"));
				k1.setString(2, request.getParameter("zqid"));
				k1.executeUpdate();k1.close();response.sendRedirect("strat.jsp");
			}
		}
		}
		con.close();
		
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}




%>
<body>

</body>
</html>